import { reqSearch, reqSearchItem, reqSearchDetail } from "@/api/search/index";

const state = {
  searchInfoList: [],
  searchItemList: [],
  searchDetailList: {},
};
const mutations = {
  GETSEARCHINFO(state, data) {
    state.searchInfoList = data.hotKeywordVOList;
  },
  GETSEARCHITEM(state, data) {
    state.searchItemList = data;
  },
  GETSEARCHDETAIL(state, data) {
    state.searchDetailList = data || {};
  },
  RESETSEARCHDETAIL(state, data) {
    state.searchDetailList = data;
  },
};
const actions = {
  async getSearchInfo({ commit, state, dispatch }) {
    let res = await reqSearch();

    commit("GETSEARCHINFO", res.data);
  },
  // 历史记录
  async getSearchItem({ commit, state, dispatch }, obj) {
    let res = await reqSearchItem(obj);

    commit("GETSEARCHITEM", res.data);
  },
  // 搜索列表
  async getSearchDetail({ commit, state, dispatch }, data) {
    let res = await reqSearchDetail(data);

    commit("GETSEARCHDETAIL", res.data);
  },

  // 重置detailList
  resetSearchDetail({ commit, state, dispatch }) {
    commit("RESETSEARCHDETAIL", {});
  },
};

const getters = {
  //分类tag数组
  categoryL1List(state) {
    return state.searchDetailList.categoryL1List;
  },
  // 商品详细信息
  directlyList(state) {
    console.log(state.searchDetailList.directlyList);
    return state.searchDetailList.directlyList;
   
  },
};

export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
};
